import { PageVo, R, Subject, SubjectQueryVo } from "./model";
import request from "../utils/request"
import { ElMessage } from "element-plus";

export const listPage = (currentPage: number, pageSize: number, subjectQueryVo?: SubjectQueryVo) => {
    // "list?page=&size=&name=..." 
    //console.log("subjectQueryVo"+subjectQueryVo?.title);
     
    return request<R<PageVo<Subject>>>({
        url: "/api/subject",
        method: "GET",
        // URL参数 ?key=value& 
        params: {
            currentPage: currentPage,
            pageSize: pageSize,
            ...subjectQueryVo // 对象拓展运算符
        }
    })
        .then((response) => {
            return response;
        });
}

export const getById = (id: string) => {
    // ES6模板字符串 
    let uri = `/api/subject/${id}`;
    // function axios(config: AxiosRequest) { 
    return request<R<Subject>>({
        url: uri,
        method: 'GET'
    })
        .then((response) => {
            return response;
        });
}


export const save = (subject: Subject) => {
    return request<R<string>>({
        url: "/api/subject",
        method: 'POST',
        data: subject
    })
        .then((response) => {
            // response.data.data: string 
            return response;
        });
}



export const update = (subject: Subject) => {
    return request<R<string>>({
        url: "/api/subject",
        method: 'PUT',
        data: subject
    })
        .then((response) => {
            return response;
        });
}

export const remove = (id: string) => {
    // ES6模板字符串
    let uri = `/api/subject/${id}`;
    return request<R<string>>({
        url: uri,
        method: 'DELETE'
    })
        .then((response) => {
            return response;
        });
}